package com.chinaisafe.gateway;

import com.chinaisafe.gateway.sdk.annotation.EnableAutoAuthorizationGateway;
import com.chinaisafe.gateway.sdk.annotation.EnableCustomLoadBalanceRuleGateway;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * GatewayApplication
 * 启动类
 * @author xuefu.shu
 * @date 2024-07-03 10:42
 */
@SpringBootApplication
@EnableAutoAuthorizationGateway
@EnableCustomLoadBalanceRuleGateway
@Slf4j
public class GatewayApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(GatewayApplication.class, args);
        log.info("=============== GatewayApplication 启动成功 ===============");

        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String property = env.getProperty("server.servlet.context-path");
        String path = property == null ? "" :  property;
        log.info("----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "\n\t" +
                "------------------------------------------------------------");
    }

}
